<?php
/**
 * Created by PhpStorm.
 * User: zmit
 * Date: 8/9/17
 * Time: 5:53 PM
 */
namespace AdminBundle\Controller;


class PersonalController extends AdminController
{
    public function personalListAction()
    {

        if(!$this->isPageLogined()){
            return $this->render('AdminBundle:Auth:login.html.twig');
        }
        $conn = $this->get("database_connection");
        $data["category"] = $conn->fetchAll("SELECT * FROM company_category WHERE 1 ");
        $data["attribute"] = $conn->fetchAll("SELECT * FROM company_attribute WHERE 1 ");
        $data['teac_admin'] = $conn->fetchAll("SELECT id,nickname FROM admin WHERE admin_role_id = 4 AND district_id = '". $this->get("session")->get("district_id") ."'");

        return $this->render("AdminBundle:Personal:personalList.html.twig",array("data"=>$data));
    }



    public function editPersonalAction($id)
    {
        if(!$this->isPageLogined()){
            return $this->render('AdminBundle:Auth:login.html.twig');
        }

        $conn = $this->get("database_connection");
        $data = $conn->fetchAssoc("SELECT * FROM user WHERE id = '". $id ."'");

        if(empty($id)){
            $data = array("id"=>$id);
        }

        $company_sql = "SELECT id, name, status, admin_id FROM company WHERE";
        if($this->this_admin_role_id == 4){

            $company_sql .= " admin_id = '". $this->this_admin_id ."' ";

        } else {

            $company_sql .= " district_id = '". $this->this_district_id ."' ";

        }
        // 获取企业列表
        $data['company'] = $conn->fetchAll($company_sql);
        return $this->render("AdminBundle:Personal:editPersonal.html.twig",array("data"=>$data));
    }
}